home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SGI Varsity Update 1998 August
/
SGI Varsity Update 1998 August.iso
/
dist
/
dist6.5
/
il_dev.idb
/
usr
/
include
/
il
/
ilPolyDef.h.z
/
ilPolyDef.h
Wrap
C/C++ Source or Header
|
1998-07-29
|
10KB
|
290 lines
#if 0
Copyright (c) 1991 SGI All Rights Reserved
THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF SGI
The copyright notice above does not evidence any
actual or intended publication of such source code,
and is an unpublished work by Silicon Graphics, Inc.
This material contains CONFIDENTIAL INFORMATION that
is the property of Silicon Graphics, Inc. Any use,
duplication or disclosure not specifically authorized
by Silicon Graphics is strictly prohibited.
RESTRICTED RIGHTS LEGEND:
Use, duplication or disclosure by the Government is
subject to restrictions as set forth in subdivision
(c)(1)(ii) of the Rights in Technical Data and Computer
Software clause at DFARS 52.227-7013, and/or in similar
or successor clauses in the FAR, DOD or NASA FAR
Supplement. Unpublished- rights reserved under the
Copyright Laws of the United States. Contractor is
SILICON GRAPHICS, INC., 2011 N. Shoreline Blvd.,
Mountain View, CA 94039-7311
#endif
#ifndef _ilPolyDef_h_
#define _ilPolyDef_h_
/* Defines some nice little structures and methods for polynomials.
*
* Note: this file is included by C code so general comments must use
* the C commenting convention.
*
* Contents:
* ilPolyCoeff1D: coefficients for univariate 7th-degree polynomial
* ilPolyCoeff2D: coefficients for bivariate 7th-degree polynomial
* ilPoly1D: univariate 7th-degree polynomial
* ilPoly2D: bivariate 7th-degree polynomial
* ilAffine2D: bivariate 1st-degree polynomial
*
*/
#include <ifl/iflCoord.h>
#ifdef __cplusplus
struct ilPoly2D; // forward reference
#endif
/*
* Coefficients for seventh degree univariate polynomials:
*/
struct ilPolyCoeff1D { float con, x, x2, x3, x4, x5, x6, x7; };
/*
* Coefficients for seventh degree bivariate polynomials:
*/
struct ilPolyCoeff2D {
float con,
y, x,
y2, xy, x2,
y3, xy2, x2y, x3,
y4, xy3, x2y2, x3y, x4,
y5, xy4, x2y3, x3y2, x4y, x5,
y6, xy5, x2y4, x3y3, x4y2, x5y, x6,
y7, xy6, x2y5, x3y4, x4y3, x5y2, x6y, x7;
};
/*
* Univariate polynomials in X up to degree 7.
*
* p(X) = x_deg*X^deg + ... + x*X + con
*/
struct ilPoly1D {
int degree; /* degree of polynomial */
struct ilPolyCoeff1D c; /* polynomial coefficients (up to 7) */
#ifdef __cplusplus
enum { maxDegree = 7 }; // maximum degree polynomials supported
//ilPoly1D() {} // null constructor
// Construct a one-variable polynomial in X from a two-variable
// polynomial in X and Y given a specified Y value.
//
ilPoly1D(const ilPoly2D &cf, double y);
#endif /* __cplusplus */
};
/* First degree, two-variable polynomials in X and Y:
*
* p(X, Y) = x*X + y*Y + con
*/
struct ilAffine2D {
float con, /* polynomial constant coefficient */
y, x; /* polynomial first degree coefficients */
#ifdef __cplusplus
ilAffine2D() {} // null constructor
// Construct a first degree polynomial given all of its coefficients.
//
ilAffine2D(float Con, float X, float Y) { init(Con, X, Y); }
// Construct a first degree polynomial from a general Nth degree
// polynomial. We have to defer the actual definition until after the
// definition of the general Nth degree polynomial class so we can
// implement an inlined version.
//
inline ilAffine2D(const ilPoly2D &uc);
// Initialize a first degree polynomial given all of its coefficients.
//
ilAffine2D &init(float Con, float X, float Y)
{ con = Con; x = X; y = Y; return *this; }
// Assign a general Nth degree polynomial to a first degree polynomial.
// Defer definition till after definition of Nth degree polynomial class.
//
inline ilAffine2D &operator=(const ilPoly2D& uc);
// Need to define the first degree to first degree assignment operator
// now since the above assignment operator definition losses us the
// default one the C++ normally gives us ...
//
ilAffine2D &operator=(const ilAffine2D& uc)
{ return init(uc.con, uc.x, uc.y); }
// Create the identity polynomial for variable ``dim'' where dim is equal
// to either 'x' or 'y'. The resulting polynomial will translate p(X, Y)
// to X or Y, respectively.
//
ilAffine2D &identity(char dim)
{ return init(0.0, dim == 'x', dim == 'y'); }
// Return result of evaluating the polynomial for (u, v).
//
float operator()(double u, double v) const
{ return x*u + y*v + con; }
float operator()(const iflXYdouble &uv) const
{ return x*uv.x + y*uv.y + con; }
float operator()(const iflXYfloat &uv) const
{ return (double)x*uv.x + (double)y*uv.y + con; }
// Return the functional composition of this polynomial with two other
// first degree two-variable polinomials:
//
// this(uc(r, s), vc(r, s))
//
ilAffine2D operator()(const ilAffine2D &uc, const ilAffine2D &vc) const
{
// note: calculate all the new coefficients in double precision
return ilAffine2D((double)x*uc.con + (double)y*vc.con + con,
(double)x*uc.x + (double)y*vc.x,
(double)x*uc.y + (double)y*vc.y);
}
// Form the functional composition of this polynomial with two other Nth
// degree two-variable polinomials and store the result as our new
// polynomial coefficients. Return a reference to this.
//
// this'(r, s) = this(uc(r, s), vc(r, s))
//
ilAffine2D &compose(const ilAffine2D &uc, const ilAffine2D &vc)
{
// XXX must generate intermediate result instead of simply passing
// XXX new coefficients to inlined init() method since a bug in the
// XXX compiler (#262091) causes new coefficients to be stored before
// XXX completely evaluating all the new coefficients.
// note: calculate all the new coefficients in double precision
ilAffine2D result((double)x*uc.con + (double)y*vc.con + con,
(double)x*uc.x + (double)y*vc.x,
(double)x*uc.y + (double)y*vc.y);
*this = result;
return *this;
}
#endif /* __cplusplus */
};
/* General two-variable polynomials in X and Y up to degree 7.
*
* p(X, Y) = x_deg*X^deg + y_deg*Y^deg + ... + x*X + y*Y + con
*/
struct ilPoly2D {
int degree; /* degree of polynomial */
struct ilPolyCoeff2D c; /* polynomial coefficients (up to 7) */
#ifdef __cplusplus
enum { maxDegree = 7 }; // maximum degree polynomials supported
ilPoly2D() {} // null constructor
// Construct general two-variable polynomial from a first degree
// two-variable polynomial. Note that this constructor depends on
// the mapping for the storage for the various polynomials to be the
// same.
//
ilPoly2D(const ilAffine2D &uc) { degree = 1; *(ilAffine2D *)&c = uc; }
// Do the same thing for assignments from first degree two-variable
// polynomials.
//
ilPoly2D &operator=(const ilAffine2D &uc)
{ degree = 1; *(ilAffine2D *)&c = uc; return *this; }
// Need to define the Nth degree to Nth degree assignment operator
// now since the above assignment operator definition losses us the
// default one the C++ normally gives us ...
//
const ilPoly2D &operator=(const ilPoly2D &uc)
{ degree = uc.degree; c = uc.c; return *this; }
// Create the identity polynomial for variable ``dim'' where dim is equal
// to either 'x' or 'y'. The resulting polynomial with translate p(X, Y)
// to X or Y, respectively.
//
ilPoly2D &identity(char dim)
{
degree = 1;
c.con = 0.0;
c.x = (float)(dim=='x');
c.y = (float)(dim=='y');
return *this;
}
// Return result of evaluating the polynomial for (u, v).
//
float operator()(double u, double v) const;
float operator()(const iflXYdouble &uv) const
{ return operator()(uv.x, uv.y); }
float operator()(const iflXYfloat &uv) const
{ return operator()(uv.x, uv.y); }
// Return the X and Y derivatives, respectively, of the polynomial at
// point (x,y).
//
float dx(double u, double v) const;
float dx(const iflXYdouble& uv) const
{ return dx(uv.x, uv.y); }
float dx(const iflXYfloat& uv) const
{ return dx(uv.x, uv.y); }
float dy(double u, double v) const;
float dy(const iflXYdouble& uv) const
{ return dy(uv.x, uv.y); }
float dy(const iflXYfloat& uv) const
{ return dy(uv.x, uv.y); }
// Return the functional composition of this polynomial with two other
// Nth degree two-variable polinomials:
//
// this(uc(X, Y), vc(X, Y))
//
ilPoly2D operator()(const ilPoly2D &uc, const ilPoly2D &vc) const;
// Form the functional composition of this polynomial with two other Nth
// degree two-variable polinomials and store the result as our new
// polynomial coefficients. Return a reference to this.
//
// this'(X, Y) = this(uc(X, Y), vc(X, Y))
//
ilPoly2D &compose(const ilPoly2D &uc, const ilPoly2D &vc);
// Return TRUE if the other polynomial is equal to this one and FALSE
// otherwise.
//
int operator==(const ilPoly2D &rhs) const;
int operator!=(const ilPoly2D &rhs) const { return !(*this == rhs); }
#endif /* __cplusplus */
};
#ifdef __cplusplus
inline ilAffine2D::ilAffine2D(const ilPoly2D &uc) { *this = uc; }
inline ilAffine2D& ilAffine2D::operator=(const ilPoly2D& uc)
{
return init(uc.c.con, uc.degree == 0 ? 0.0 : uc.c.x,
uc.degree == 0 ? 0.0 : uc.c.y);
}
#endif
#ifndef __cplusplus
typedef struct ilPolyCoeff1D ilPolyCoeff1D;
typedef struct ilPoly1D ilPoly1D;
typedef struct ilAffine2D ilAffine2D;
typedef struct ilPolyCoeff2D ilPolyCoeff2D;
typedef struct ilPoly2D ilPoly2D;
#endif /* __cplusplus */
#endif /* _ilPolyDef_h_ */